﻿using System;
using System.Configuration;

public partial class Home : System.Web.UI.Page
{
    private int gval;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["userSession"] != null) lblUser.Text = Session["userSession"].ToString();
    }

    protected void btnShow_Click(object sender, EventArgs e)
    {
        string op = ConfigurationManager.AppSettings["Operation"];
        if (op.ToLower().Equals("evenodd"))
            lblResult.Text = Evenodd(Convert.ToInt32(txtNo.Text));
        else if (op.ToLower().Equals("factorial"))
            lblResult.Text = "Factorial is" + Factorial(Convert.ToInt32(txtNo.Text));
    }
    protected void btnDetails_Click(object sender, EventArgs e)
    {
        //Response.Redirect("~/Details.aspx?var1=55");
        Response.Redirect("~/Details.aspx?var1=" + txtNo.Text);
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        ViewState["myValue"] = Convert.ToInt32(txtNo.Text);
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        int a = Convert.ToInt32(ViewState["myValue"]);
        int x = a + 10;
        lblResult.Text = "2nd  value is " + x;
    }

    private string Evenodd(int n)
    {
        return n % 2 == 0 ? "No. is Even" : "No. is odd";
    }
    private long Factorial(int n)
    {
        long fact = 1;
        while (n >= 1)
        {
            fact = fact * n;
            n--;
        }
        return fact;
    }

}